// ---------------------------------------------------------------------
//
// -- 弹出层（模态）
// -- author £
//
// ---------------------------------------------------------------------

cc.Class({
    extends: cc.Component,

    properties: {
        gameMask: require('GameMask'),
        defaultWindow: cc.Prefab,
        windowLayer: cc.Node,
    },

    // use this for initialization
    onLoad: function () {
        this.windowLayer.on('closeWindow', this.closeWindowHandler, this);
        require('Alert').bindUI(this);
    },

    start: function () {
        
    },

    open: function (prefab, ...args) {
        if (!prefab)
            prefab = this.defaultWindow;

        let node = cc.instantiate(prefab),
            comp = node.getComponent('AlertWindow');

        comp.isAdded = false;
        comp.show(this.windowLayer);
        comp.setData(...args);
        this.gameMask.show();
    },

    closeWindowHandler: function () {
        if (this.windowLayer.childrenCount === 1)
            this.gameMask.hide();
    },

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },
});
